<style lang="scss" scoped>
.search {
  width: 100%;
  overflow: hidden;
}
.list {
  dl {
    display: flex;
    padding: 10px;
    dt {
      width: 50px;
      height: 100px;
      img {
        width: 50px;
        height: 50px;
      }
      margin: 0 10px;
    }
    dd {
      .name {
        font-size: 20px;
        font-weight: 800;
      }
    }
  }
}
</style>

<template>

  <div class="search">
    <!-- 搜索框 -->
    <van-nav-bar
    title="搜索"
    left-arrow
    @click-left="$router.back()"
  />
    <van-search
      v-model="searchValue"
      show-action
      placeholder="请输入搜索关键词"
      @search="handSearch"
    >
      <template #action>
        <div @click="handSearch">搜索</div>
      </template>
    </van-search>
  
    <div style="padding: 10px" >
      <div style="display: flex; justify-content: space-between">
        <h3>历史记录</h3>
        <span @click="nosocomium = []">X</span>
      </div>
      <div style="height: 90px; overflow: hidden">
        <van-space wrap>
          <van-tag
            size="large"
            v-for="(v, i) in nosocomium"
            :key="i"
            @click="handclick(v)"
            >{{ v }}</van-tag
          >
        </van-space>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {  ref, watch } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const isSearch = ref(false)
const searchValue = ref('')
const handSearch = () => {
  router.push('/SearchList?searchValue=' + searchValue.value)
  // 将仓库内容进行去重   
  nosocomium.value = [...new Set([searchValue.value, ...nosocomium.value])]
  isSearch.value = true
}
// 将搜索框的内容存入本地仓库
const nosocomium = ref<string[]>(JSON.parse(localStorage.getItem('nosocomium') || '[]'))
// 实时监听取出仓库内容
watch(nosocomium, () => {
  localStorage.setItem('nosocomium', JSON.stringify(nosocomium.value))
})
const handclick=(v:string)=>{
   router.push('/SearchList?searchValue=' + v)
}



</script>
